import React, { Component } from "react";
import "./login.scss";
import { Form, Input, Button } from "antd";
import { UserOutlined, LockOutlined } from "@ant-design/icons";
import { LoginAjax ,getreact} from "../../utils/api"
import { withRouter } from "react-router-dom";
import userinfo from "../../mobx/userinfo";
// 登录
@withRouter
class Login extends Component {
    render() {
        const onFinish = (value) => {
            LoginAjax(value).then(res => {
                if (res.type) {
                    // 存
                    localStorage.setItem("pwd", value.userpwd)
                    sessionStorage.setItem("token", res.token)
                    userinfo.changeUserinfo(res.result)

                    this.props.history.push("/main")
                }
            })
        }
        return (
            <div className="login-box">
                <div className="fontsize">安逸医院内部管理系统登录</div>

                <Form
                    name="normal_login"
                    className="login-form"
                    onFinish={onFinish}
                    initialValues={{
                        remember: true,
                    }}
                >
                    <Form.Item
                        name="username"
                        rules={[
                            {
                                required: true,
                                message: "请输入您的用户名!",
                            },
                        ]}
                    >
                        <Input
                            prefix={<UserOutlined className="site-form-item-icon" />}
                            placeholder="Username"
                        />
                    </Form.Item>
                    <Form.Item
                        name="userpwd"
                        rules={[
                            {
                                required: true,
                                message: "请输入您的密码!",
                            },
                        ]}
                    >
                        <Input
                            prefix={<LockOutlined className="site-form-item-icon" />}
                            type="password"
                            placeholder="Password"
                        />
                    </Form.Item>

                    <Form.Item>
                        <Button
                            type="primary"
                            htmlType="submit"
                            className="login-form-button"
                        >
                            登录
            </Button>
                        <Form.Item>
                            <span className="spantext">
                                本系统有六个测试的用户账号为root、doctor、nurse、checkstand、用户
                                。 所有用户的密码皆为123。其中最高权限是root用户
              </span>
                        </Form.Item>
                    </Form.Item>
                </Form>
            </div>
        );
    }
}
export default Login